using System;
using System.Collections.Generic;
using System.Text;
using Emlyn.Applications.Scratch.Graphics.Dragon1;
using Microsoft.DirectX.Direct3D;
using System.Drawing;

namespace Emlyn.Applications.Scratch.Graphics.Tools
{
    public class EAnimatedDirectionSprite: EMultiTextureSprite
    {
        int _framesPerDirection = 1;
        int _currentFrameForDirection = 0;
        private EDirection _facing;
        int _animationStepLength = 1;
        int _currentAnimationTick = 0;

        public EAnimatedDirectionSprite(
            DirectXWrapper aWrapper, 
            Size aSize, 
            Textures aTextures, 
            int aFramesPerDirection, 
            int aAnimationStepLength
            )
            : base(aWrapper, aSize, aTextures)
        {
            _framesPerDirection = aFramesPerDirection;
            _animationStepLength = aAnimationStepLength;
        }

        protected virtual void SetFacing(EDirection aFacing)
        {
            _facing = aFacing;
        }

        public EDirection Facing
        {
            get { return _facing; }
            set { SetFacing(value); }
        }

        protected override Texture GetCurrentTexture()
        {
            Texture retval = null;

            _currentAnimationTick++;

            if (_currentAnimationTick >= _animationStepLength)
            {
                _currentAnimationTick = 0;
                _currentFrameForDirection = (_currentFrameForDirection + 1) % _framesPerDirection;
            }

            retval = _textures[((int)_facing * _framesPerDirection) + _currentFrameForDirection];

            return retval;
        }
    }
}
